package regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AtLeastBothNumberAndLetters {

    public static void main(final String[] args) {

        String pattern = ".*(\\d.*[a-zA-Z]|[a-zA-Z].*\\d).*";
        Pattern compile = Pattern.compile(pattern);

        String string = "12345678";
        Matcher matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abcDEFghig";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "1234abDF";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "2b";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abDF1234";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "b2";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc123abc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "b2b";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "123abc123";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "2b2";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "123abc123!";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "123abc 123";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 91; i < 97; i++) {

            stringBuffer.append((char) i);
        }
        stringBuffer.append(1);

        String pattern1 = ".*(\\d.*\\w|\\w.*\\d).*";
        compile = Pattern.compile(pattern1);
        string = stringBuffer.toString();
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));
    }
}
